package top.kaoshanji.ch08.pair1;

/**
 * author kaoshanji
 * ^_^
 * create time 2024/11/28 16:35
 */
public class ArrayAlg {

    public static Pair<String> minmax(String[] a) {

        if (a == null || a.length == 0) {
            return null;
        }

        // 计算出最小值和最大值
        String min = a[0];
        String max = a[0];

        for (int i = 1; i < a.length; i++) {
            if (min.compareTo(a[i]) > 0) {
                min = a[i];
            }
            if (max.compareTo(a[i]) < 0) {
                max = a[i];
            }

        }

        return new Pair<>(min, max);
    }

}
